<?php

namespace App\Admin\Controllers;

use App\crm_tourist;

use Encore\Admin\Form;
use Encore\Admin\Grid;
use Encore\Admin\Facades\Admin;
use Encore\Admin\Layout\Content;
use App\Http\Controllers\Controller;
use Encore\Admin\Controllers\ModelForm;
use App\Admin\Extensions\Tools\Duanxin;
use App\Admin\Extensions\Tools\DuanxinykGender;
class crm_touristController extends Controller
{
    use ModelForm;

    
    public function index()
    {
        return Admin::content(function (Content $content) {

            $content->header('游客管理');
            $content->description('游客列表');

            $content->body($this->grid());
        });
    }

    /**
     * Edit interface.
     *
     * @param $id
     * @return Content
     */
    public function edit($id)
    {
        return Admin::content(function (Content $content) use ($id) {

            $content->header('游客管理');
            $content->description('游客修改');

            $content->body($this->form()->edit($id));
        });
    }

    /**
     * Create interface.
     *
     * @return Content
     */
    public function create()
    {
        return Admin::content(function (Content $content) {

            $content->header('游客管理');
            $content->description('游客添加');

            $content->body($this->form());
        });
    }

    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        return Admin::grid(crm_tourist::class, function (Grid $grid) {
            // $grid->disableCreation();
            
            $grid->id('序号')->sortable();
            $grid->tourist_type('游客类别');
            $grid->tourist_typename('单位名称');
            $grid->tourist_name('姓名');
            $grid->tourist_sex('性别');
            $grid->tourist_phone('电话');
            $grid->tourist_number('身份证');
            $grid->filter(function ($filter) {
                // 去掉默认的id过滤器
                $filter->disableIdFilter();
                $filter->equal('tourist_type','游客类别')->select(['单位'=>'单位','个人'=>'个人']);
                $filter->like('tourist_typename','单位名称');
                $filter->like('tourist_name','姓名');
                $filter->like('tourist_phone','电话');
            });
            $grid->tools(function ($tools) {
                $tools->append(new DuanxinykGender());//调用隐藏的弹出层按钮
                $tools->batch(function ($batch) {
                    $batch->disableDelete();//禁用批量删除
                    $batch->add('短信发送', new Duanxin());
                });
            });
            $grid->disableExport();//禁用导出数据按钮
            $grid->disableCreation();       //把新增框干掉
            $script_addones=<<<EOT
                $("#duanxin").css("display","none");

EOT;
                Admin::script($script_addones); 
        });
    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        return Admin::form(crm_tourist::class, function (Form $form) {

            $form->display('id', 'ID');

            // $form->display('created_at', 'Created At');
            // $form->display('updated_at', 'Updated At');
            $form->tools(function (Form\Tools $tools) {
                // 去掉跳转列表按钮
                $tools->disableListButton();
            });
        });
    }
}
